<include file="Public/header" />
<title>我的桌面</title>
</head>
<body>
<div class="page-container">
    <div class="mt-20">
        <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
            <table class="table table-border table-bordered table-bg table-hover table-sort dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
                <thead>
                <tr class="text-c" role="row">
                    <th width="25" class="sorting_disabled" rowspan="1" colspan="1" aria-label="" style="width: 25px;"><input type="checkbox" name="" value=""></th>
                    <th width="80" class="sorting_desc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1">ID</th>
                    <th width="200">产品名称</th>
                    <th width="60">类目</th>
                    <th width="60">仓库名称</th>
                    <th width="60">仓库编码</th>
                    <!-- <th width="75">价格</th> -->
                    <th width="60">第一单位名称</th>
                    <th width="60">第一单位编码</th>
                    <th width="60">第一单位数量</th>
					<!-- <th width="60">第一单位规格</th> -->
					<th width="60">第二单位名称</th>
                    <th width="60">第二单位编码</th>
                    <th width="60">第二单位数量</th>
					<!-- <th width="60">第二单位规格</th> -->
                    <!-- <th width="60">HSCODE</th> -->
                    <th width="60">商品编码</th>
                    <th width="80">预计到货时间</th>
                    <th width="80">推送状态</th>
                    <th width="80">操作者</th>
                    <th width="120">添加时间</th>
                </tr>
                </thead>
                <tbody>
                <foreach name="list" item="data">
                    <tr class="text-c odd" role="row">
                        <td><eq name="data.is_push" value="0"><input type="checkbox" value="<{$data.id}>" name=""></eq></td>
                        <td class="sorting_1"><{$data.id}></td>
                        <td class="text-l"><{$data.name}></td>
                        <td><{$data.category}></td>
                        <td><{$data.warehouse_name}></td>
                        <td><{$data.warehouse_code}></td>
                        <!-- <td><{$data.price}></td> -->
                        <td class="td-status">
                            <select <eq name="data.is_push" value="1">disabled="disabled"</eq> tabindex="<{$data.unit_name}>" name="unit_name">
                                <option tabindex="<{$data.u_n}>"><{$data.u_name}></option>
                                <if condition="$data.u_name_t neq null">
                                    <option tabindex="<{$data.u_n_t}>"><{$data.u_name_t}></option>
                                </if>
                            </select>
                        </td>
                        <td class="td-status"><{$data.unit_no}></td>
                        <td><span class="p_count"><{$data.count}></span></td>
                        <!-- <td class="td-status"><{$data.hs_code}></td> -->
						 <!-- <td class="td-status"><{$data.standard}></td> -->
						 <td class="td-status"><{$data.unit_t_name}></td>
						 <td class="td-status">
						 <if condition="$data.unit_t_no neq 'undefined'">
							<{$data.unit_t_no}>
						 </if>
						 </td>
						 <td class="td-status"><{$data.unit_t_count}></td>
						 <!-- <td class="td-status"><{$data.unit_t_goods_spec}></td> -->
                        <td class="td-status"><{$data.goods_no}></td>
                        <td class="td-status">
                            <input type="text" name="expected_time" value="<{$data.expected_time}>" onfocus="WdatePicker({el:$dp.$('d12')})" id="logmin" class="input-text Wdate" style="width:120px;">
                        </td>
                        <td class="td-status">
                            <span class="label label-success radius">
                            <eq name="data.is_push" value="1">
                                已推送
                                <else/>
                                未推送
                            </eq>
                            </span>
                        </td>
                        <td class="td-status"><{$data.operator}></td>
                        <td><{$data.created_at}></td>
                    </tr>
                </foreach>
                </tbody>
            </table>
            <div style="margin-top: 12px;" class="Huialert Huialert-info"><i class="icon-remove"></i>只有在“未推送”的状态下才能“点击数量”或者选择“单位”实现更改。其他字段均不能更改</div>
            <div style="margin-top: 32px;">
                <if condition="data.is_push neq null">
                <neq name="data.is_push" value="1">
                    <neq name="is_examined" value="4">
                        <a href="javascript:;" tabindex="<{$Think.get.id}>" onclick="delAll()" class="btn btn-danger radius"><i class="Hui-iconfont"></i> 批量删除</a>
                         <a href="javascript:;" tabindex="<{$Think.get.id}>" onclick="add_again(this)" class="btn btn-success radius"><i class="Hui-iconfont"></i>继续为该计划入库单添加产品</a>
                    </neq>
                </neq>
                </if>
                <a href="javascript:;" onclick="cancel()" class="btn btn-default radius">取消</a>

				<!-- <a href="javascript:;" onclick="importexcelAll(<{$Think.get.id}>)" class="btn btn-primary radius"><i class="Hui-iconfont"></i>批量导入</a> -->
            </div>
        </div>
    </div>
    <include file="Public/footer" />
    <include file="Public/footer_js" />
    <script>
		function importexcelAll(id){
            var index=layer.open({
                type: 2,
                title: '导入数据',
                shadeClose: true,
                shade: 0.5,
                area: ['1000px', '150px'],
                content: '__MODULE__/import/importListproduct/id/'+id+'/'+Math.random() //iframe的url
            });
        }
        function add_again(_this){
            var id=$(_this).attr('tabindex');
            location.href="__CONTROLLER__/detail_add/id/"+id;
        }
        var new_count='';
        $(".p_count").click(function (){
            if("<{$data.is_push}>"!=0){
                layer.msg('当前状态不允许修改');
                return false;
            }
            $(this).attr('contenteditable',true);
            new_count=$(this).html();
            $(this).css({'background-color':'#f99','padding':'2px 12px'});
            $(this).focus();
        });
        $(".p_count").blur(function (){
            $(this).attr('contenteditable',false);
            $(this).css({'background-color':'#fff','padding':'0'});
            var id=$(this).parents('tr').find("input:checkbox").val();
            var count=$(this).html();
            if(isNaN($(this).html()) || $(this).html()==new_count){
                $(this).html(new_count);
                return true;
            }
            editCount(id,count);
        });

        var new_c='';
        $("input[name=expected_time]").click(function (){
            if("<{$data.is_push}>"!=0){
                layer.msg('当前状态不允许修改');
            }
            new_c=$(this).val();
        });
        $("input[name=expected_time]").blur(function (){
            var id=$(this).parents('tr').find("input:checkbox").val();
            var count=$(this).val();
            if($(this).val()=='' || $(this).val()==new_c){
                $(this).prop('value',new_c);
                return true;
            }
            editTime(id,count);
        });
        $("select[name=unit_name]").change(function (){
            var id=$(this).parents('tr').find("input:checkbox").val();
            var unit_name=$(this).val();
            var unit_no=$(this).find("option:selected").attr('tabindex');
            editUnit(id,unit_name,unit_no)
        });
        function editCount(id,count){
            if("<{$data.is_push}>"!=0){
                layer.msg('当前状态不允许修改');
            }
            $.post('__CONTROLLER__/product_editD',{
                id:id,
                count:count,
                type:'count',
            },function (msg){
                layer.msg(msg.data);
                if(msg.flag==1){
                    setTimeout(function (){
                        location.reload();
                    },800);
                }
            },'json');
        }
        function editTime(id,time){
            if("<{$data.is_push}>"!=0){
                layer.msg('当前状态不允许修改');
                return false;
            }
            $.post('__CONTROLLER__/product_editD',{
                id:id,
                time:time,
                type:'time',
            },function (msg){
                layer.msg(msg.data);
                if(msg.flag==1){
                    setTimeout(function (){
                        location.reload();
                    },800);
                }
            },'json');
        }
        function editUnit(id,unit_name,unit_no){
            if("<{$data.is_push}>"!=0){
                layer.msg('当前状态不允许修改');
                return false;
            }
            $.post('__CONTROLLER__/product_editD',{
                id:id,
                unit_name:unit_name,
                unit_no:unit_no,
                type:'unit',
            },function (msg){
                layer.msg(msg.data);
                if(msg.flag==1){
                    setTimeout(function (){
                        location.reload();
                    },800);
                }
            },'json');
        }
        function delAll(){
            if("<{$data.is_push}>"!=0){
                layer.msg('当前状态不允许删除');
                return false;
            }
            var all_ipt=$("#DataTables_Table_0_wrapper input[type=checkbox]:checked");
            var group_id='';
            for(var i=0;i<all_ipt.length;i++){
                if(all_ipt.eq(i).val()!==''){
                    group_id+='@'+all_ipt.eq(i).val();
                }
            }
            if(group_id.substring(1)==''){
                layer.msg('请勾选要删除的信息');
                return false;
            }
            del(group_id.substring(1));
        }
        function del(id){
            $.get('__MODULE__/List/detail_del',{
                id:id,
            },function (msg){
                layer.msg(msg.data);
                if(msg.flag==1){
                    setTimeout(function (){
                        location.reload();
                    },800);
                }
            },'json');
        }
        function cancel(){
           history.back();
        }
        (function (){
            for(var i=0;i<$("select[name=unit_name]").length;i++){
                $("select[name=unit_name]").eq(i).prop('value',$("select[name=unit_name]").eq(i).attr('tabindex'));
            }
        })();
    </script>
</body>
</html>